from lib.clock import rtc_clock,ticker_clock
from lib.sensors.ssd1306.oled import OLED
from lib.config.index import sensor_config

oled_config = sensor_config.get_sensor("ssd1306")
scl = oled_config["scl"]
sda = oled_config["sda"]
width = oled_config["width"]
height = oled_config["height"]

clock = rtc_clock.RTC_CLOCK()
clock.sync_network_time()

timer = ticker_clock.TickerClock(500)

_oled = OLED(scl, sda, width, height)

def show_time():
    global _oled
    # print(clock.get_date_str(),clock.get_time_str())
    _oled.rect(0, 0, 128, 30, 0)
    # print(clock.get_time_str())
    _oled.text(clock.get_date_str(), 0, 0)
    _oled.text(clock.get_time_str(), 0, 10)
    _oled.show()

while True:
    if timer.check():
        show_time()

